package com.yang.action;

import com.yang.entity.User;
import com.yang.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/updateUser")
public class UserUpdateAction extends HttpServlet {
    UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = new User();
        String id = req.getParameter("id");
        user.setId(Integer.parseInt(id));
        String login = req.getParameter("login");
        user.setLogin(login);
        String name = req.getParameter("name");
        user.setName(name);
        String pwd = req.getParameter("pwd");
        user.setPwd(pwd);
        String sex = req.getParameter("sex");
        user.setSex(sex);
        String phone = req.getParameter("phone");
        user.setPhone(phone);
        String photo = req.getParameter("photo");
        user.setPhoto(photo);
        String birthday = req.getParameter("birthday");
        user.setBirthday(Date.valueOf(birthday));
        String master = req.getParameter("master");
        user.setMaster(master);
        int num = userService.updateUserById(user);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

